<template>
  <yt-page title="特殊作业列表" :rightData="rightData">
    <yt-group ref="group" :searchApi="searchApi" :group="false">
      <yt-card slot-scope="scope"
        btn="查看更多详情"
        @btn-click="goDetailPage(scope.id)"
        class="no-padding"
        >
        <yt-cell border="none" label="作业负责人" :value="scope.work_principal"></yt-cell>
        <yt-cell border="none" label="作业监护人" :value="scope.work_guardian"></yt-cell>
        <yt-cell border="none" label="作业类别" :value="scope.work_type"></yt-cell>
        <yt-cell border="none" label="申请日期" :value="scope.req_date"></yt-cell>
        <yt-cell border="none" label="作业开始时间" labelWidth="120px" :value="scope.start_time"></yt-cell>
        <yt-cell border="none" label="作业结束时间" labelWidth="120px" :value="scope.end_time"></yt-cell>
      </yt-card>
    </yt-group>
    <yt-popup pos="right" v-model="search" :mask="true" slot="alert">
      <yt-page class="page" :flex="true" :leftData="[]" title="筛选条件">
        <yt-form>
          <yt-inlineSelect title="申请日期" v-model="condition.req_date" :list="TIME" :x="3" label="key" val="endTime"></yt-inlineSelect>
          <yt-inlineSelect title="作业类别" v-model="condition.work_type" :list="workTypeDic" :x="3" label="D_text" val="D_code" multiple></yt-inlineSelect>
          <yt-btn-group slot="btn" :shadow="false">
            <yt-btn theme="white" @click="search = false">关闭</yt-btn>
            <yt-btn @click="onSearch">确定</yt-btn>
          </yt-btn-group>
        </yt-form>

      </yt-page>
    </yt-popup>
  </yt-page>
</template>

<script>
import { commonApi } from '@/common/api/commonApi.js'
import { ReplaceDictionary } from '@/common/utils/index.js'
import { formatTime } from '@/common/plugin/index.js'
import moment from 'moment'
const TIME = [
  { key: '近三天', endTime: moment().subtract(3, 'days').format('YYYY-MM-DD') },
  { key: '近一周', endTime: moment().subtract(7, 'days').format('YYYY-MM-DD') },
  { key: '近一个月', endTime: moment().subtract(30, 'days').format('YYYY-MM-DD') },
  { key: '近三个月', endTime: moment().subtract(90, 'days').format('YYYY-MM-DD') },
  { key: '近半年', endTime: moment().subtract(180, 'days').format('YYYY-MM-DD') },
  { key: '近一年', endTime: moment().subtract(365, 'days').format('YYYY-MM-DD') }
]
export default {
  data () {
    return {
      TIME,
      rightData: [{
        font: 'yt-icon yt-icon-search',
        click: () => {
          this.search = !this.search
        }
      }],
      search: false,
      condition: {
				req_date: '',
				start_time: '',
				end_time: '',
				work_type: []
			},
			workTypeDic: [],
      searchApi: async ({ skip, limit }) => {
        let {work_type = [], req_date} = this.condition
        work_type = work_type.length ? { work_type } : {}
        let condition = {...work_type}
        let param = Object.assign({ equalTo: this.$route.query, containedIn: condition, greaterThanOrEqualTo: { req_date: req_date }, lessThanOrEqualTo: { req_date: moment().format('YYYY-MM-DD') } }, { skip, limit, include: ['req_departName'] })
        let p = [
					commonApi.dictionary('work_type'),
          commonApi.search('spe_tickets_manager', param)
        ]
				let [workTypeDic, data] = await Promise.all(p)

				this.workTypeDic = workTypeDic

        return ReplaceDictionary(data, { work_type: workTypeDic })
      }
    }
  },
  methods: {
    onSearch () {
      this.search = false
      this.$refs.group.startPull()
    },
    goDetailPage (id) {
      this.$router.$push({ path: '/special-work/detail', query: {objectId: id} })
    }
  }
}
</script>

<style lang="stylus" scoped>
  >>> .flex
    display flex
    justify-content space-between
    padding 10px
    border-bottom .5px solid #f5f5f5
  >>> .no-padding .yt-cell-label
    padding 0
</style>
